<#assign ctrl_base_name = "CalendarViewExpBarControlBase"/>
<#assign import_block>
import CodeListService from "@service/app/codelist-service";
<#if view.getPSSysCounterRef?? && view.getPSSysCounterRef()?? && view.getPSSysCounterRef().getPSAppCounter()??>
<#assign appCounter = view.getPSSysCounterRef().getPSAppCounter() />
import  ${srfclassname('${appCounter.getCodeName()}')}CounterService  from '@/counter/${srffilepath2(appCounter.getCodeName())}/${srffilepath2(appCounter.getCodeName())}-counter';
</#if>
</#assign>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>
<#ibizinclude>
../@MACRO/FUNC/MACRO.ftl
</#ibizinclude>

<#if ctrl.getXDataPSControl()??>
<#assign xDataControl = ctrl.getXDataPSControl() />

    /**
     * 导航视图名称
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public navViewName: any = {
<#if xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
        ${calendarItem.getItemType()}: "<#if calendarItem.getNavPSAppView?? && calendarItem.getNavPSAppView()??><#assign navPSAppView = calendarItem.getNavPSAppView() />${srffilepath2(navPSAppView.getCodeName())}</#if>"<#if calendarItem_has_next>,</#if>
  </#list>
</#if>
    };

    /**
     * 导航参数
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public navParam: any = {
<#if xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
        ${calendarItem.getItemType()}: {
            navigateContext:<#if calendarItem.getPSNavigateContexts?? && calendarItem.getPSNavigateContexts()??><@getNavigateContext calendarItem /><#else>null</#if>,
            navigateParams:<#if calendarItem.getPSNavigateParams?? && calendarItem.getPSNavigateParams()??><@getNavigateParams calendarItem /><#else>null</#if>
        }<#if calendarItem_has_next>,</#if>
  </#list>
</#if>
    };

    /**
     * 导航过滤项
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public navFilter: any = {
<#if xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
        ${calendarItem.getItemType()}: "<#if calendarItem.getNavFilter?? && calendarItem.getNavFilter()??>${calendarItem.getNavFilter()}</#if>"<#if calendarItem_has_next>,</#if>
  </#list>
</#if>
    };

    /**
     * 导航关系
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public navPSDer: any = {
<#if xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
        ${calendarItem.getItemType()}: "<#if calendarItem.getNavPSDER?? && calendarItem.getNavPSDER()??>n_${calendarItem.getNavPSDER().getPSPickupDEField().getCodeName()?lower_case}_eq</#if>"<#if calendarItem_has_next>,</#if>
  </#list>
</#if>
    };
</#if>

<#if ctrl.getPSControls()??>
    <#assign controls = ctrl.getPSControls()/>
    <#list controls as singleControl>
        <#if singleControl.getControlType() == "TOOLBAR">

    ${P.getCtrlCode(singleControl, 'CONTROL.vue').code}
        </#if>
    </#list>
</#if>



<#macro getSearchPlaceholder ctrl>
  <#assign isdrawcComma = false />
  <#if ctrl.getPSAppDataEntity?? && ctrl.getPSAppDataEntity()?? && ctrl.getPSAppDataEntity().getAllPSAppDEFields?? && ctrl.getPSAppDataEntity().getAllPSAppDEFields()??>
    <#list ctrl.getPSAppDataEntity().getAllPSAppDEFields() as field>
      <#if field.isEnableQuickSearch()>
        <#if isdrawcComma>，<#else><#assign isdrawcComma = true /></#if><#t>
        ${field.getPSDEField().getLogicName()}<#t>
      </#if>
    </#list>
  </#if>
</#macro>
    /**
     * 搜索字段名称
     * 
     * @type {(string)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public placeholder="<@getSearchPlaceholder ctrl />";

    /**
     * 呈现模式，可选值：horizontal或者vertical
     * 
     * @public
     * @type {(string)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public showMode:string ="<#if view.getSideBarLayout()?? && view.getSideBarLayout() == "LEFT">horizontal<#else>vertical</#if>";

    /**
     * 控件高度
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public ctrlHeight: number = <#if ctrl.getHeight()??>${ctrl.getHeight()?c}<#else>0</#if>;
<#if view.isEnableQuickGroup()>

    /**
     * 加载快速分组模型
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public loadQuickGroupModel(){
        this.$nextTick(() => {
            <#if view.getQuickGroupPSCodeList()??>
            <#assign codelist=view.getQuickGroupPSCodeList() />
            let quickGroupCodeList:any = {tag:'${codelist.codeName}',codelistType:'${codelist.getCodeListType()}'};
            if(quickGroupCodeList.tag && Object.is(quickGroupCodeList.codelistType,"STATIC")){
                const codelist = this.$store.getters.getCodeList(quickGroupCodeList.tag);
                if (codelist) {
                    this.quickGroupModel = [...this.handleDynamicData(JSON.parse(JSON.stringify(codelist.items)))];
                } else {
                    <#noparse>console.log(`----${quickGroupCodeList.tag}----代码表不存在`);</#noparse>
                }
            }else if(quickGroupCodeList.tag && Object.is(quickGroupCodeList.codelistType,"DYNAMIC")){
                this.codeListService.getItems(quickGroupCodeList.tag,{},{}).then((res:any) => {
                    this.quickGroupModel = res;
                }).catch((error:any) => {
                    <#noparse>console.log(`----${quickGroupCodeList.tag}----代码表不存在`);</#noparse>
                });
            }
            </#if>
        });
    }
</#if>
    
    /**
     * ${ctrl.name}的选中数据事件
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public ${ctrl.name}_selectionchange(args: any [], tag?: string, $event2?: any): void {
        let tempContext:any = {};
        let tempViewParam:any = {};
        if (args.length === 0) {
            this.calcToolbarItemState(true);
            return ;
        }
        const arg:any = args[0];
        if(this.context){
            Object.assign(tempContext,JSON.parse(JSON.stringify(this.context)));
        }
        switch(arg.itemType) {
<#if xDataControl?? && xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
    <#if calendarItem.getPSAppDataEntity()??>
      <#assign _appde = calendarItem.getPSAppDataEntity() />
            case "${calendarItem.getItemType()}":
                Object.assign(tempContext,{ ${_appde.getCodeName()?lower_case} : arg.${_appde.getCodeName()?lower_case}});
                Object.assign(tempContext,{srfparentdename:'${_appde.getCodeName()}',srfparentkey:arg['${_appde.getCodeName()?lower_case}']});
                if(this.navFilter && this.navFilter['${calendarItem.getItemType()}'] && !Object.is(this.navFilter['${calendarItem.getItemType()}'],"")){
                    Object.assign(tempViewParam,{[this.navFilter['${calendarItem.getItemType()}']]:arg['${_appde.getCodeName()?lower_case}']});
                }
                if(this.navPSDer && this.navFilter['${calendarItem.getItemType()}'] && !Object.is(this.navPSDer['${calendarItem.getItemType()}'],"")){
                    Object.assign(tempViewParam,{[this.navPSDer['${calendarItem.getItemType()}']]:arg['${_appde.getCodeName()?lower_case}']});
                }
                if(this.navParam && this.navParam['${calendarItem.getItemType()}'] && this.navParam['${calendarItem.getItemType()}'].navigateContext && Object.keys(this.navParam['${calendarItem.getItemType()}'].navigateContext).length >0){
                    let _context:any = this.$util.computedNavData(arg,tempContext,tempViewParam,this.navParam['${calendarItem.getItemType()}'].navigateContext);
                    Object.assign(tempContext,_context);
                }
                if(this.navParam && this.navParam['${calendarItem.getItemType()}'] && this.navParam['${calendarItem.getItemType()}'].navigateParams && Object.keys(this.navParam['${calendarItem.getItemType()}'].navigateParams).length >0){
                    let _params:any = this.$util.computedNavData(arg,tempContext,tempViewParam,this.navParam['${calendarItem.getItemType()}'].navigateParams);
                    Object.assign(tempViewParam,_params);
                }
                break;
    </#if>
  </#list>
</#if>
        }
        this.selection = {};
        Object.assign(this.selection, { view: { viewname: this.navViewName[arg.itemType] }, context:tempContext,viewparam:tempViewParam });
        this.calcToolbarItemState(false);
        this.$emit('selectionchange',args);
        this.$forceUpdate();
    }

    /**
     * ${ctrl.name}的load完成事件
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public ${ctrl.name}_load(args:any, tag?: string, $event2?: any){
        this.calcToolbarItemState(true);
        this.$emit('load',args);
    }

    /**
     * 设置导航区工具栏禁用状态
     *
     * @param {boolean} state
     * @return {*} 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public calcToolbarItemState(state: boolean) {
        let _this: any = this;
        const models:any = _this.${ctrl.getCodeName()?lower_case}_toolbarModels;
        if (models) {
            for (const key in models) {
                if (!models.hasOwnProperty(key)) {
                    return;
                }
                const _item = models[key];
                if (_item.uiaction && (Object.is(_item.uiaction.target, 'SINGLEKEY') || Object.is(_item.uiaction.target, 'MULTIKEY'))) {
                    _item.disabled = state;
                }
                _item.visabled = true;
                if (_item.noprivdisplaymode && _item.noprivdisplaymode === 6) {
                    _item.visabled = false;
                }
            }
            this.calcNavigationToolbarState();
        }
    }

    /**
     * 计算导航工具栏权限状态
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public calcNavigationToolbarState(){
        let _this: any = this;
        // 界面行为
        <#assign ModelsName>${ctrl.getCodeName()?lower_case}_toolbarModels</#assign>
        if(_this.${ModelsName}){
        <#if ctrl.getPSAppDataEntity?? && ctrl.getPSAppDataEntity()??>
        <#assign curAppEntity = ctrl.getPSAppDataEntity() />
            const curUIService:${srfclassname('${curAppEntity.getCodeName()}')}UIService  = new ${srfclassname('${curAppEntity.getCodeName()}')}UIService();
            ViewTool.calcActionItemAuthState({},_this.${ModelsName},curUIService);
        </#if>
        }
    }

    /**
    * 执行搜索
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
    */
    public onSearch($event:any) {
        <#if ctrl.getXDataPSControl()??>
        <#assign xDataControl = ctrl.getXDataPSControl()/>
        let calendar:any = this.$refs.${xDataControl.getName()};
        calendar.searchEvents({ query: this.searchText });
        </#if>
    }

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>